package com.fileoperation;

import android.app.ActivityManager;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016-12-19.
 */

public class CommonUtils {

    /**
     * 重新调整textview的compoundDrawables的大小
     *
     * @param size  新的drawable尺寸
     * @param index 调整的drawable的索引序号
     * @param view  需要调整的目标textview
     */
    public static void resizeDrawable(int size, int index, TextView view) {
        Drawable[] drawables = view.getCompoundDrawables();
        Drawable target = drawables[index];
        if (target != null) {
            target.setBounds(0, 0, size, size);
        }
        view.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
    }


    public static byte[] concat(byte[] a, byte[] b) {
        byte[] c= new byte[a.length+b.length];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, 0, c, a.length, b.length);
        return c;
    }


    public static boolean isServiceRunning(Context mContext, String className) {

        boolean isRunning = false;
        ActivityManager activityManager = (ActivityManager)
                mContext.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> serviceList
                = activityManager.getRunningServices(30);

        if (!(serviceList.size()>0)) {
            return false;
        }

        for (int i=0; i<serviceList.size(); i++) {
            if (serviceList.get(i).service.getClassName().equals(className) == true) {
                isRunning = true;
                break;
            }
        }
        return isRunning;
    }
}
